package cn.xgj.sfzy.service.impl;

import cn.xgj.sfzy.entity.Appointment;
import cn.xgj.sfzy.entity.CourseEvaluation;
import cn.xgj.sfzy.entity.CourseType;
import cn.xgj.sfzy.entity.User;
import cn.xgj.sfzy.mapper.AppointmentMapper;
import cn.xgj.sfzy.mapper.CourseEvaluationMapper;
import cn.xgj.sfzy.mapper.CourseTypeMapper;
import cn.xgj.sfzy.mapper.UserMapper;
import cn.xgj.sfzy.service.UserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * @ClassName userServiceImpl
 * @Description TODO
 * @Author xgj
 * @Date 2024年10月21日 14:40
 * @Version 1.0
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;
    @Autowired
    private CourseEvaluationMapper courseEvaluationMapper;
    @Autowired
    private AppointmentMapper appointmentMapper;

    @Override
    public User login(String userName, String userPassword) {
        return userMapper.selectByUsernameAndPassword(userName,userPassword);
    }

    @Override
    public int add(User user) {
        return userMapper.insert(user);
    }

    @Override
    public int edit(User user) {
        return userMapper.update(user);
    }

    @Override
    public int remove(Integer id) {
        List<Appointment> appointmentList = appointmentMapper.findByUserId(id);
        List<CourseEvaluation> courseEvaluationList = courseEvaluationMapper.findByUserId(id);
        if (courseEvaluationList.size()!=0 || appointmentList.size()!=0){
            return -1;
        }else{
            return 0;
        }
//        return 0;

    }

    @Override
    public List<User> findAll(User user) {
        return userMapper.find(user);
    }

    @Override
    public User findById(Integer id) {
        return userMapper.findById(id);
    }

    @Override
    public PageInfo<User> findByPage(Integer pageNum, Integer pageSize, User user) {
        PageHelper.startPage(pageNum,pageSize);
        List<User> list = userMapper.find(user);
        PageInfo<User> info = new PageInfo<User>(list);
        return info;
    }

}

